package com.hee.erp.modules.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.SysDictType;
import com.hee.erp.modules.entity.SysLog;
import com.hee.erp.modules.entity.SysUser;
import com.hee.erp.modules.service.ISysDictTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-03-21
 */
@RestController
@RequestMapping("/modules/sysDictType")
public class SysDictTypeController {

    @Autowired
    ISysDictTypeService sysDictTypeService;
    //四个方法 listByPage,getDetailById,delById,save

    @PostMapping("/listByPage")
    @ApiOperation(value = "listByPage",notes = "{\n" +
            "\"current\":1,\n" +
            "\"pageSize\":10\n" +
            "}")
    public R<IPage<SysDictType>> listByPage(@RequestBody JSONObject params){
        Integer pageSize = params.getInteger("pageSize");
        Integer current = params.getInteger("current");
        IPage<SysDictType> page = new Page<>(current,pageSize);
        LambdaQueryWrapper<SysDictType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(SysDictType::getCreateTime);
        sysDictTypeService.page(page,queryWrapper);
        return R.success(page);
    }

    @ApiOperation(value = "getDetailById")
    @GetMapping("/getDetailById")
    public R<SysDictType> getById(String id){
        SysDictType entity = sysDictTypeService.getById(id);
        return R.success(entity);
    }

    @PostMapping("/save")
    @ApiOperation(value = "save")
    public R<Boolean> save(@RequestBody SysDictType entity){
        sysDictTypeService.saveOrUpdate(entity);

        return R.success(true);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        sysDictTypeService.removeById(id);
        return R.success(true);
    }

}

